﻿using System;
using System.Reflection;

namespace VSCodeCustomAttribute
{
    class Program
    {
        static void Main(string[] args)
        {
          /*   TestClass1 testClass1 = new TestClass1();
            Type type = testClass1.GetType();
            PropertyInfo[] propertyInfos = type.GetProperties();
            FieldInfo[] fieldInfos = type.GetFields();
            
            Console.WriteLine(propertyInfos.Length.ToString());
            foreach (var attr in propertyInfos)
            {
                Console.WriteLine(attr.ToString());
            }

              foreach (var attr in fieldInfos)
            {
                Console.WriteLine(attr.ToString());
            } */

            //获取表明
            Type type = typeof(User);
            Console.WriteLine("Table名称:");
            Console.WriteLine(AttributeProcess.GetTableName(type));
            PropertyInfo[] props = type.GetProperties();
            Console.WriteLine("列名称:");
            foreach(var property in props)
            {
                Console.WriteLine(AttributeProcess.GetColumnName(property));
            }

        }
    }

    [Serializable]
    [AttributeUsage(AttributeTargets.All)]
    class Check : Attribute
    {
        //构造函数
        public Check()
        {

        }

        private int _MaxLength = 0;
        public int MaxLength
        {

            get
            {
                return _MaxLength;
            }
            set
            {
                if (value > _MaxLength)
                {
                    Console.WriteLine("不能超过MaxLength最大值设定");
                }
                else
                {
                    _MaxLength = value;
                }
            }
        }

    }

    [Check(MaxLength = 8)]
    class Customer
    {
        private string _CustomerCode;
        public string CustomerCode
        {

            get;
            set;
        }

        /*  private string _CustomerName;
         public string CustomerName
         {
             get;
             set;
         } */
    }
}
